import type { RouteLocationNormalized, Router } from 'vue-router';
import { useUserStore } from '~/store/modules/user';
import { loginPagePath } from '~/router/menu';

export function setupAuthenticateGuard(router: Router) {
  router.beforeEach(async (to: RouteLocationNormalized) => {
    let user = useUserStore();
    if (!user.isAuthenticated() && to.path !== loginPagePath) {
      return {
        path: loginPagePath
      };
    }
  });
}
